/*
 * @Author: Clark
 * @Email: haixuanwoTxh@gmail.com
 * @Date: 2023-02-01 13:46:27
 * @LastEditors: Clark
 * @LastEditTime: 2023-02-02 09:21:53
 * @Description: file content
 */
#include "apue.h"
#include <sys/wait.h>

int main(void)
{
    FILE *fpin = NULL;
    char line[MAXLINE] = {0};

    if ((fpin = popen("myuclc", "r")) == NULL)
    {
        err_sys("popen error");
    }

    while (1)
    {
        fputs("prompt> ", stdout);
        fflush(stdout);

        // read from pipe
        if (fgets(line, MAXLINE, fpin) == NULL)
        {
            break;
        }

        if (fputs(line, stdout) == EOF)
        {
            err_sys("fputs error to pipe");
        }
    }

    if (pclose(fpin) == -1)
    {
        err_sys("pclose error");
    }
    putchar('\n');
    exit(0);
}
